// 抽象父类
// 负责设置宽高，位置，速度(单位duration内移动多少px)和dom
class RectTangle {
    constructor(width, height, left, top, xSpeed, ySpeed, dom) {
        this.width = width
        this.height = height
        this.left = left
        this.top = top
        this.xSpeed = xSpeed
        this.ySpeed = ySpeed
        this.dom = dom
    }

    // onMove() {

    // }

    // 用于渲染显示子类
    render() {
        this.dom.style.width = this.width + 'px'
        this.dom.style.height = this.height + 'px'
        this.dom.style.left = this.left + 'px'
        this.dom.style.top = this.top + 'px'
    }

    // 提供一个移动方法
    move(duration) {
        let newLeft = this.left + this.xSpeed * duration
        let newTop = this.top + this.ySpeed * duration
        // console.log(newLeft);   
        this.left = newLeft
        this.top = newTop

        // 当每次移动之前都要判断一下是否需要归位
        if(this.onMove) {
            this.onMove()
        }

        this.render()
    }
}